<template>
<div class="vue-box sbot sbot-fluid">
  <!-- 参数栏 -->
  <div class="c-panel">
    <el-form :inline="true">
      <!-- 表单 -->
      <sa-item v-model="m.name" type="text" name="参数名" br />
      <sa-item v-model="m.icon" type="text" name="图标" br />
      <sa-item v-model="m.color" type="color" name="颜色" br />
      <sa-item v-model="m.code" type="text" name="识别码" br />
      <sa-item v-model="m.clazzCode" type="text" name="类别编码" br />
      <sa-item v-model="m.type" type="enum" jtype="3" :jv="dims.PROP_TYPE" name="参数类型" br />
      <sa-item v-model="m.valType" type="enum" jtype="3" :jv="dims.PROP_VAL_TYPE" name="值类型" br />

      <sa-item v-model="m.val" type="img" name="参数值" v-if="m.valType==='0'" br></sa-item>
      <sa-item v-model="m.val" type="text" name="参数值" v-else br></sa-item>
      <sa-item v-model="m.defaultVal" type="img" name="默认值" v-if="m.valType==='0'" br />
      <sa-item v-model="m.defaultVal" type="text" name="默认值" v-else br />

      <sa-item v-model="m.status" type="enum" jtype="3" :jv="dims.YES_OR_NO" name="启用状态" br />
      <sa-item v-model="m.note" type="text" name="描述" br />
      <sa-item v-model="m.sort" type="num" name="序号" br />
      <sa-item name="" br class="s-ok">
        <el-button type="primary" icon="el-icon-plus" @click="ok()">保存</el-button>
      </sa-item>
    </el-form>
  </div>
</div>
</template>

<script>
export default {
  name: 'prop-add',
  props: {
    param: Object
  },
  data() {
    return {
      // 超级对象
      m: this.createModel(),
      dims: this.param.dims
    }
  },
  methods: {
    createModel() {
      return {
        id: this.param.id,
        name: this.param.name,
        code: this.param.code,
        val: this.param.val,
        type: this.param.type,
        valType: this.param.valType,
        defaultVal: this.param.defaultVal,
        status: this.param.status,
        note: this.param.note,
        sort: this.param.sort
      }
    },
    // 变更
    ok: function () {
      // 表单校验
      let m = this.m;
      sa.checkNull(m.name, '请输入参数名');
      sa.checkNull(m.code, '请输入识别码');
      sa.checkNull(m.status, '请确认是否启用');
      sa.checkNull(m.type, '请确认参数类型');
      sa.checkNull(m.val, '请确认参数值');

      // 添加
      sa.ajax(m.id ? '/prop/update' : '/prop/add', m, function (res) {
        if (res.code == 200) {
          sa.alert(res.msg, function () {
            this.m = this.createModel();
            sa.closeModel();
            sa.currView().f5();
          }.bind(this));
        }
      }.bind(this), {
        type: 'post'
      });
    }
  }
}
</script>

<style scoped></style>
